package cn.signalpha.modules.resource.controller;

import cn.signalpha.common.constant.AppConstant;
import cn.signalpha.common.constant.MsgConstant;
import cn.signalpha.common.utils.Assert;
import cn.signalpha.core.boot.ctrl.BaseController;
import cn.signalpha.core.tool.api.R;
import cn.signalpha.core.tool.utils.Func;
import cn.signalpha.modules.resource.dto.AttachDTO;
import cn.signalpha.modules.resource.entity.Attach;
import cn.signalpha.modules.resource.entity.AttachCategory;
import cn.signalpha.modules.resource.service.IAttachCategoryService;
import cn.signalpha.modules.resource.service.IAttachService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 附件表 控制器
 */
@RestController
@AllArgsConstructor
@RequestMapping(AppConstant.APPLICATION_RESOURCE_NAME + "/admin/attach")
@Api(value = "附件", tags = "附件")
public class AttachController extends BaseController {

	private final IAttachService attachService;
	private final IAttachCategoryService attachCategoryService;

	@PostMapping("/transfer")
	@ApiOperation(value = "附件转移", notes = "")
	public R submit(@Valid @RequestBody AttachDTO.TransferDTO attachDTO) {
		AttachCategory attachCategory = attachCategoryService.getById(attachDTO.getCategoryId());
		Assert.isNull(attachCategory, MsgConstant.OBJECT_NULL);
		Attach attach = Attach.builder().categoryId(attachDTO.getCategoryId()).build();
		attachService.update(attach, Wrappers.<Attach>lambdaUpdate().in(Attach::getId, Func.toLongList(attachDTO.getIds())));
		return R.status(true);
	}

}
